package com.x.erp.service;

import java.util.List;
import java.util.Map;

import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Component;

import com.alibaba.dubbo.config.annotation.Service;
import com.x.erp.dao.ModelConfDao;
import com.x.erp.dao.ModelDao;
import com.x.erp.model.Model;
import com.x.erp.model.ModelConf;
import com.x.erp.rpc.ModelRpcService;
import com.x.framework.exception.BusinessException;
import com.x.framework.exception.ExceptionCode;
import com.x.framework.service.BaseService;

@Component
@Service(interfaceName = "com.x.erp.rpc.ModelRpcService", timeout = 60000)
public class ModelService extends BaseService implements ModelRpcService {

	@Autowired
	private ModelDao modelDao;

	@Autowired
	private ModelConfDao modelConfDao;

	@Override
	public List<Model> selectModelList(Model model) {
		try {
			return modelDao.selectModelList(model);
		} catch (Exception e) {
			throw new BusinessException(ExceptionCode.EXCEPTION_CODE0013, e);
		}
	}

	@Override
	public List<Model> selectModelAndConfList(Model model) {
		try {
			return modelDao.selectModelAndConfList(model);
		} catch (Exception e) {
			throw new BusinessException(ExceptionCode.EXCEPTION_CODE0013, e);
		}
	}

	/**
	 * 根据ID查询车型配置
	 * 
	 * @param modelConf
	 * @return
	 */
	@Override
	public List<ModelConf> selectModelConfList(ModelConf modelConf) {
		try {
			return modelConfDao.selectModelConfList(modelConf);
		} catch (Exception e) {
			throw new BusinessException(ExceptionCode.EXCEPTION_CODE0013, e);
		}
	}

	/**
	 * 查询车型关系
	 * 
	 * @param model
	 * @param marketId
	 * @return
	 */
	@Override
	public Model selectModelMapping(Model model, String marketId) {
		try {
			return modelDao.selectModelMapping(model, marketId);
		} catch (Exception e) {
			throw new BusinessException(ExceptionCode.EXCEPTION_CODE0013, e);
		}
	}

    @Override
    public void insertModelList(Model model) {
        try {
            modelDao.insertModelList(model);
        } catch (Exception e) {
            throw new BusinessException(ExceptionCode.EXCEPTION_CODE0001, e);
        }
    }

    @Override
    public void updateLibraryModelList(Model model) {
        try {
            modelDao.updateLibraryModelList(model);
        } catch (Exception e) {
            throw new BusinessException(ExceptionCode.EXCEPTION_CODE0001, e);
        }
    }

    @Override
    public Model getSimpleModel(Map<String, Object> model) {
        try {
            return modelDao.getSimpleModel(model);
        } catch (Exception e) {
            throw new BusinessException(ExceptionCode.EXCEPTION_CODE0001, e);
        }
    }

}
